(function(fontSize) {
        let emitevt = false;
        let canBuy = 0;
       // let k = setInterval(()=>cc.jsl.user && (cc.jsl.user.roles.forEach(t=>t.own = 1),  clearInterval(k)), 1000)
        // 次版本变化,数据局不可以用
        const version = 'v0.0.5';
        // ui相关
        let createElement = document.createElement.bind(document)
        , createTextNode = document.createTextNode.bind(document)
        , floor = Math.floor.bind(Math);
        // 存储
        const _sym = '_sym';
        let status = undefined;
        // id不填写,是全部
        const pass = (type,id)=>{
            if(id=='count'){return;}
            let d = status[type].data;
            if (id) {
                d[id].passed = true;
                status[type].passed++;
            } else {
                for (let s in d) d[s].passed = true;
                status[type].passed = status[type].count;
            }
        }
        ;
        // 恢复 id不填写,是全部
        const unpass = (type,id)=>{
            if(id=='count'){return;}
            let d = status[type].data;
            if (id) {
                d[id].passed = false;
                status[type].passed--;
            } else {
                for (let s in d)
                  d[s].passed = false;
                status[type].passed = 0;
            }
        }
        ;
        const reset = (type)=>{
            if (type) {
                unpass(type);
            } else {
                for (let t in status) {
                    t !== 'version' && unpass(t);
                }
            }
        }
        ;

        // 获取或者新生成
        let saved = window.localStorage.getItem(_sym);
        if (saved) {
            status = JSON.parse(saved);
        }
        let keep = (t)=>{
            let currentVersion = version.split('.');
            let savedVeersion = t.split('.');
            for (let i = 0; i < currentVersion.length - 1; i++) {
                if (currentVersion[i] != savedVeersion[i])
                    return false;
            }
            return true;
        }
        ;
        if (!status || !status.version || !keep(status.version)) {
            window.localStorage.removeItem(_sym);
            // 初始化值
            let {small, big, maket} = window.data;
            status = JSON.parse(JSON.stringify({
                small,
                big,
                maket
            }));
            Object.assign(status.small, {
                tag: 's',
                position: 'left',
                count: 0,
                passed: 0
            });
            Object.assign(status.big, {
                tag: 'b',
                position: 'left',
                count: 0,
                passed: 0
            });
            Object.assign(status.maket, {
                tag: 'm',
                position: 'right',
                count: 0,
                passed: 0
            });

            function formatPrice(t) {
                if (!parseInt(t)) {
                    return t;
                } else {
                    let tag = '';
                    let _p = t;
                    if (t < 0) {
                        tag = '-';
                        _p = -t;
                    }
                    let m = _p.toString();
                    if (m.length > 4)
                        return tag + m[0] + 'w' + (m[1] == 0 ? '' : m[1]);
                    if (m.length > 3)
                        return tag + m[0] + 'k' + (m[1] == 0 ? '' : m[1]);
                    return t;
                }

                // return t / 10000 >= 1 ? `${floor(t / 10000)}w${floor((t % 10000) / 1000) === 0 ? '' : floor((t % 10000) / 1000)}` : (t / 1000 >= 1 ? `${floor(t / 1000)}k${floor((t % 1000) / 100) === 0 ? '' : floor((t % 1000) / 100)}` : t);
            }

            function is_guopiao(ga) {
                return ga._title.includes("GRIT") || ga._title.includes("LSSP") || ga._title.includes("GJMT") || ga._title.includes("UFO") || ga._title.includes("股票")
            }

            function is_fangcan(ga) {
                return ga._title.includes("41T")
            }

            function gp(ga){
                if(ga.item3 == "每两股并一股"){
                    return "-";
                }else if(ga.item3 == "股票一分为二"){
                    return "+";
                }else {
                    return ga.item2;
                }
            }

            function detail_small(ga) {
                return is_guopiao(ga) ? "" + gp(ga) : is_fangcan(ga) ? formatPrice(ga.item3) + "|" + ga.item4 : "" + ga.item1
            }

            // 替换器生成器
            function nameReplacerFactory(ga) {
                return (ha)=>{
                    ga.forEach((ia)=>{
                        ha = ha.replace(ia.f, ia.t)
                    }
                              );
                    return ha
                }
            }

            let c = {};
            let dump = [];
            var replacer_small = nameReplacerFactory([{
                f: "股票-聚砂砾游戏公司",
                t: "GRIT"
            }, {
                f: "股票-茅酒",
                t: "GJMT"
            }, {
                f: "股票-乐薯公司",
                t: "LSSP"
            }, {
                f: "用爱发电有限公司",
                t: "LOVE"
            }, {
                f: "指数基金-财商300",
                t: "UFO"
            }, {
                f: "银行存单",
                t: "CD"
            }, {
                f: "2室1厅住宅",
                t: "241T"
            }, {
                f: "3室1厅89平住宅",
                t: "341T"
            }, {
                f: "兼职开网店",
                t: "茶店"
            }, {
                f: "兼职摆地摊",
                t: "地摊"
            }, {
                f: "浮雕螭龙玉佩",
                t: "玉佩"
            }, {
                f: "黄金戒指",
                t: "戒指"
            }, {
                f: "超市抽奖",
                t: "抽奖"
            }, {
                f: "袁大头",
                t: "银元"
            }, {
                f: "房产受损",
                t: "房损"
            }]);
            for (let i in status.small.data) {
                let item = status.small.data[i];
                if (item) {
                    status.small.count++;
                    let p = item.title;
                    c[p] = (c[p] || 0) + 1;
                    item._title = replacer_small(p);
                }
            }
            dump = [];
            for (let i in c)
                1 < c[i] && dump.push(i);
            for (let i in status.small.data) {
                let item = status.small.data[i];
                if (item) {
                    item._id = `s-${item.ID}`;
                    let _t = item._title;
                    item._title = dump.includes(item.title) ? `[${_t}][${detail_small(item)}]` : `[${_t}]`;
                }
            }

            let replacer_maket = nameReplacerFactory([{
                f: "求购",
                t: ""
            }, {
                f: "2室1厅住宅",
                t: "241T"
            }, {
                f: "3室1厅89平住宅",
                t: "341T"
            }, {
                f: "公寓楼房",
                t: "楼房"
            }, {
                f: "公寓",
                t: "248"
            }, {
                f: "有限合伙人公司出售",
                t: "合伙"
            }, {
                f: "茶叶品牌网店",
                t: "茶店"
            }, {
                f: "花卉店",
                t: "花店"
            }, {
                f: "纪念品专卖店",
                t: "纪念"
            }, {
                f: "中医理疗馆",
                t: "中医"
            }, {
                f: "电动车制造企业",
                t: "电车"
            }, {
                f: "兼职生意业绩提升",
                t: "兼职"
            }, {
                f: "通货膨胀爆发",
                t: "通胀"
            }, {
                f: "收藏家玉佩",
                t: "玉佩"
            }, {
                f: "收藏家银元",
                t: "银元"
            }, {
                f: "金价大涨",
                t: "金涨"
            }, {
                f: "金价下跌",
                t: "金跌"
            }]);
            c = {};
            for (let i in status.maket.data) {
                let item = status.maket.data[i];
                if (item) {
                    status.maket.count++;
                    let p = item.title;
                    c[p] = (c[p] || 0) + 1;
                    item._title = replacer_maket(p);
                }
            }
            dump = ['兼职生意业绩提升'];
            for (let i in c)
                1 < c[i] && dump.push(i);
            for (let i in status.maket.data) {
                let item = status.maket.data[i];
                if (item) {
                    let _t = item._title;
                    item._id = `m-${item.ID}`;
                    item._title = dump.includes(item.title) ? `[${_t}][${formatPrice(item.price)}]` : `[${_t}]`;
                }
            }

            var replacer_big = nameReplacerFactory([{
                f: "电动车制造企业",
                t: "电车"
            }, {
                f: "纪念品专卖店",
                t: "纪念"
            }, {
                f: "中医养生馆",
                t: "中医"
            }, {
                f: "小型花卉店",
                t: "花店"
            }, {
                f: "海鲜自助餐厅",
                t: "海鲜"
            }, {
                f: "时尚火锅店",
                t: "火锅"
            }, {
                f: "沙县小吃",
                t: "沙县"
            }, {
                f: "房产严重受损",
                t: "受损"
            }, {
                f: "征求有限责任合伙人",
                t: "合伙"
            }, {
                f: "酒店式公寓",
                t: "酒店"
            }, {
                f: "公寓",
                t: ""
            }, {
                f: "3室1厅89平住宅",
                t: "3室"
            }]);
            c = {};
            for (let i in status.big.data) {
                let item = status.big.data[i];
                if (item) {
                    status.big.count++;
                    let p = item.title;
                    c[p] = (c[p] || 0) + 1;
                    item._title = replacer_big(p);
                }
            }
            dump = [];
            for (let i in c)
                1 < c[i] && dump.push(i);
            for (let i in status.big.data) {
                let item = status.big.data[i];
                if (item) {
                    let _t = item._title;
                    item._id = `b-${item.ID}`;
                    item._title = dump.includes(item.title) ? `[${item._title}][${formatPrice(item.item3)}|${formatPrice(item.item4)}]` : `[${_t}]`;
                }
            }
            reset();
        }
        window.onbeforeunload = un=>{
            var e = window.event || un;
            status.version = version;
            window.localStorage.setItem(_sym, JSON.stringify(status));
        }
        ;

        let _map = {
            s: 'small',
            b: 'big',
            m: 'maket'
        };
        let split = id=>id.split('-');

        // 只处理自己,界面部分自己订阅这边
        let root = Object.assign(new EventTarget(), {
            data: status,
            pass: (id)=>{
                let k = split(id);
                let t = _map[k[0]]
                , i = k[1];
                pass(t, i);
                if (status[t].passed >= status[t].count) {
                    let evt = new Event('reset');
                    evt._id = k[0];
                    root.reset(k[0]);
                    setTimeout(()=>root.dispatchEvent(evt), 1800);
                }
            }
            ,
            unpass: (id)=>{
                let k = split(id);
                unpass(_map[k[0]], k[1]);
            }
            ,
            reset: (type)=>{
                if (!type) {
                    reset();
                } else {
                    reset(_map[type]);
                }
            }
        });
        let msg = {
    GAME_START: 1,
    SELECT_ROLE: 2,
    TURN_TO_PLAYER: 3,
    DICE_REQ: 4,
    DICE_RSP: 5,
    BUY_CATD: 6,
    LOAN: 7,
    REPAY: 8,
    SELECT_CHANCE: 9,
    CHARITY: 10,
    CLEARN_ASSET: 11,
    GAME_END: 12,
    TALK: 13,
    SELLASSET: 14,
    GIVEUP: 15,
    LIFEPAY: 16,
    DATA_BACK: 17,
    LOSTJOB: 18,
    ENDRURN: 19,
    AUCTION: 20,
    END_AUCTION: 21,
    STATE_CHANGE: 22,
    SET_ROOM: 23,
    KICK_USER: 24
  }
        function log(id){
            for(let i in msg){
            if(msg[i] == id){
            console.log(i);break;;
            }
            }
        }
let prevcash = 0;
        pomelo.on("onGameData", (t) => {
            //console.log(t);
            //log(t.msgId);
            let msgId = t.msgId;
            let chanceType = t.chanceType;
            let cardType = t.cardType;
            let evt;
            let player = cc.jsl.player || cc.jsl.players.find(pl => pl && pl.hadInit && pl.user) ;
            if(player){
                let cash = Math.max(0,Math.floor( player.cashflow / 100)*1000) + player.myCash;
                let ccc = 0;
                for(let im in status.big.data){
                    let kim = status.big.data[im];
if(kim && !kim.passed && kim.item3 <= cash){ ccc++;}
                }
                canBuy = ccc;
                if(ccc !== prevcash){
                let evt = new Event('big');evt._id = 'count';
                root.dispatchEvent(evt);
                }
                prevcash = ccc;
            }
            if (msgId == 1) {
                evt = new Event('start');
            } else if (msgId == 5 && chanceType == 5) {
                evt = new Event('maket');
                evt._id = t.cardId;
            } else if (msgId == 9) {
                if (cardType == 1) {
                    evt = new Event('big');
                    evt._id = t.cardId;
                } else if (cardType == 0) {
                    evt = new Event('small');
                    evt._id = t.cardId;
                }
            }

            evt && root.dispatchEvent(evt);
        }
                 );
        let handlersMap = {
            start: e=>{
                root.reset()
            }
            ,
            maket: e=>{
                root.pass(`m-${e._id}`)
            }
            ,
            big: e=>{
                root.pass(`b-${e._id}`)
            }
            ,
            small: e=>{
                root.pass(`s-${e._id}`)
            }
            ,
            reset: e=>{
                root.reset(e._id)
            }
        };
        for (let i in handlersMap) {
            root.addEventListener(i, handlersMap[i]);
        }

        // 界面相关
        function createStyle(ga) {
            var ha = createElement("style");
            ha.styleSheet ? ha.styleSheet.cssText = ga : ha.appendChild(createTextNode(ga));
            document.getElementsByTagName("head")[0].appendChild(ha);
            return ha;
        }

        createStyle(`.flex{display: flex;flex-direction: column; }
button:focus {  outline: none;}
    .r{color: #b71313e8;background-color: ghostwhite;}
      .care{color:#ff8d00!important;}
    .h{display:none;}
    button {background-color: #0000!important;border: 0;width: 3rem;height: 3rem;}
    #b,#s,#m,button{font-size:${fontSize};position: fixed;text-align: left;background-color:rgba(33, 33, 33, 0.66);color:#9bff01;top:0;}.footer{position:fixed;display:flex;bottom:0;}`);

        let render = ()=>{
            for (let i in status) {
                if (i === 'version')
                    return;
                let data = status[i].data;
                let position = status[i].position;
                let tag = status[i].tag;
                if (document.querySelector(`div#${tag}`))
                    continue;

                let div = createElement('div');
                div.style[position] = '0';
                document.body.appendChild(div);
                div.id = `${tag}`;

                let footer = createElement('div');
                footer.style.position = 'fixed';
                footer.style[position] = '0';
                footer.style.bottom = '0';
                div.appendChild(footer);

                for (let item in data) {
                    let it = data[item];
                    if (it) {
                        let _item = createElement('div');
                        _item.innerText = it._title;
                        _item.id = it._id;
                        div.appendChild(_item);
                        it.passed && _item.classList.add('h');
                        _item.classList.add(i);
                        if(i === 'big'){
                            _item.dataset.cashflow = it.item4;
                            _item.dataset.price = it.item3;
                            if(it.item4>1000){
                                _item.classList.add('care');
                            }
                        }
                    }
                }
                //const setFooter = ()=>footer.innerText = `${status[i].count - status[i].passed} / ${status[i].count}`;
                const setFooter = () => footer.innerText = `${status[i].count - status[i].passed} / ${status[i].count} ${i === 'big'? '['+canBuy+']':''}`;
                setFooter();
                div.addEventListener('click', e=>{
                    if (emitevt && e.srcElement instanceof HTMLDivElement && e.srcElement !== div) {
                        if (e.srcElement.id) {
                            root.pass(e.srcElement.id);
                            e.srcElement.classList.add('h');
                            setFooter();
                        } else if (e.srcElement === footer) {
                            let evt = new Event('reset');
                            evt._id = tag;
                            root.reset(tag);
                            root.dispatchEvent(evt);
                        }
                    }
                }
                                    );
                let quene = [];
                let _reset = act=>{
                    act.classList.remove('h');
                    act.classList.remove('r');
                }
                let _resetAll = act=>{
                    Array.from(div.children).filter(act=>act instanceof HTMLDivElement).forEach(_reset);
                    setFooter();
                    quene.forEach(clearTimeout);
                }
                ;
                let handlersMap = {
                    start: _resetAll,
                    reset: e=>e._id === tag && _resetAll(),
                    undo: e=>{
                        let m = div.querySelector(`#${e._id}`);
                        if (m)
                            m.classList.remove('h'),
                                m.classList.remove('r')
                        setFooter();
                    }
                };

                handlersMap[i] = e=>{
                    if(i == 'big' && e._id === 'count'){
                        setFooter();return;
                    }
                    let m = div.querySelector(`#${tag}-${e._id}`);
                    if (m) {
                        m.classList.add('r');
                        let l = setTimeout(()=>{
                            m.classList.add('h'),
                                m.classList.remove('r')
                            quene = quene.filter(t=>t != l);
                        }
                                           , 6000);
                        quene.push(l);
                        setFooter()
                    }
                }
                ;

                for (let i in handlersMap) {
                    root.addEventListener(i, handlersMap[i]);
                }
            }
        }
        var ea = createElement("button");
        ea.style.position = "fixed";
        ea.style.zIndex = `1`;
        ea.style.top = ea.style.right = "0";
        document.body.appendChild(ea);
        let show = 0;
        ea.onclick = ()=>{
            render();
            let k = [['b', 'm'], ['s', 'm'], []];

            ['b', 'm', 's'].forEach(act=>{
                if (!k[show].includes(act)) {
                    let s = document.querySelector(`#${act}`);
                    s.classList.add('h');
                } else {
                    document.querySelector(`#${act}`).classList.remove('h');
                }
            }
                                   );
            show = (show + 1) % 3;
            emitevt = show === 0? !emitevt : emitevt;
        }
    }
               )('.35rem')
